package main

import (
	"fmt"
	"log"
)

func add(args ...int) int {
	sum := 0
	for _, arg := range args {
		sum += arg
	}

	return sum
}

type MyStr string

var temp string = "Hello world!"

func RemoveFromSlice(datasrc []int, index int) []int {

	if index > len(datasrc)-1 || index < 0 {
		log.Println("index invalid")
		return nil
	}

	return append(datasrc[:index], datasrc[index+1:]...)
}

func RemoveFromSliceCopy(datasrc []int, index int) []int {
	datatmp := make([]int, len(datasrc))
	copy(datatmp, datasrc)
	if index > len(datatmp)-1 || index < 0 {
		log.Println("index invalid")
		return nil
	}

	return append(datatmp[:index], datatmp[index+1:]...)
}

func makeslice() {
	s := make([]int, 5)
	s = append(s, 1, 2, 3)
	fmt.Println(s)
}

func main() {
	// add(1, 2, 3)
	// add([]int{1, 3, 5}...)

	// var newStr MyStr
	// newStr = MyStr(temp)
	// log.Println("newStr is ", newStr)

	// const pai float64 = 3.1415926
	// const (
	// 	name = "zack"
	// 	age  = 33
	// )

	//不可以将变量赋值给常量
	//const newerr = errors.New("new error")

	//nil赋值
	// var x1 interface{} = nil
	// var x2 error = nil
	// log.Println("x1 is ", x1)
	// log.Println("x2 is ", x2)

	//切片初始化
	// s := make([]int, 0)
	// s = make([]int, 5, 10)
	// s = []int{1, 2, 3, 4, 5}
	// log.Println(s)
	// datasrc := []int{6, 1, 0, 5, 2, 9}

	// data := RemoveFromSlice(datasrc, 0)
	// log.Println("data is ", data)
	// log.Println("datasrc is ", datasrc)
	// data = RemoveFromSlice(datasrc, 3)
	// log.Println("data is ", data)

	// datasrc = []int{6, 1, 0, 5, 2, 9}
	// data = RemoveFromSliceCopy(datasrc, 0)
	// log.Println("data is ", data)
	// log.Println("datasrc is ", datasrc)
	// data = RemoveFromSlice(datasrc, 3)
	// log.Println("data is ", data)
	makeslice()
}
